{include file='default/head' /}

<!-- Page content -->
<div class="page-content">
    <!-- Page title -->
    <div class="page-title">
        <div class="row justify-content-between align-items-center">
            <div class="col-md-6 mb-3 mb-md-0">
                <h5 class="h3 font-weight-400 mb-0 text-white">{$title}</h5>
            </div>
        </div>
    </div>
    <!-- Page title -->
    <!-- 主体 -->

    <div class="row">
        <div class="col-xl-12 col-md-12 col-lg-12">
            <div class="card card-fluid">
                <div class="card-header">
                    <h6 class="mb-0">收银配置</h6>
                </div>
                <div class="card-body">

                    <form id="form_data">

                    <div class="form-group">
                        <label class="form-control-label">收银台模板</label>
                            <select class="form-control" name="cashier_template">
                                {foreach name="cashier_arr" item="v" key="key"}
                                <option value="{$v}" {$v==$user['cashier_template']?"selected":""}>{$v}</option>
                                {/foreach}
                            </select>
                    </div>
                        <div class="form-group mb-1">
                            <label class="form-control-label">预选金额</label>
                            <input type="text" class="form-control" name="preselection_money" placeholder="请填写预选金额" value="{$user['preselection_money']}">
                            <div class="col-sm-12">
                                <p class="mb-0">客户付款时便于一键填写金额，每个金额用“|”隔开。最多设置6个预选金额，留空则关闭预选金额功能</p>
                            </div>
                        </div>
                        <hr/>
                        <div class="form-group">
                            <label class="form-control-label">支付商品名称 - 规则模式</label>
                            <div class="col-sm-12">
                                <p class="mb-0">请务必避免商品名称出现违规违法及敏感内容，否则支付平台可能将对你的商户号进行处理！！！</p>
                            </div>
                            <select class="form-control" id="payment_mode" name="payment_mode">
                                <option value="1" {$user['payment_mode']=="1"?"selected":""}>商户名称</option>
                                <option value="2" {$user['payment_mode']=="2"?"selected":""}>自义定名称</option>
                            </select>
                        </div>

                        <div class="form-group mb-1" id="payment_name" style="display:  {$user['payment_mode']!='2'?'none':'block'}">
                            <label class="form-control-label">支付商品名称 - 自义定名称</label>
                            <input type="text" class="form-control" name="payment_name" value="{$user['payment_name']}" placeholder="请设置自义定商品名称">
                            <div class="col-sm-12">
                                <p class="mb-0">请注意不要出现违规违法及敏感内容，否则平台将拦截支付并记录违规行为！！！时间戳变量：[time]；4位随机数变量：[rand4]；商户QQ号码：[QQ]；可以设置多个名称，每个名称用“|”隔开，多个名称时每次支付将随机选择一个。</p>
                            </div>
                        </div>

                        <br/>
                    <button type="button" class="btn btn-sm btn-primary rounded-pill" id="form_submit">确认配置</button>
                    </form>

                </div>
            </div>
        </div>
    </div>
    <!-- 主体 -->
</div>

{include file='default/bottom' /}

<script>
    $("#payment_mode").change(function (){
        var val = $(this).val();
        if (val == "2") {
            $("#payment_name").css("display", "block");
        } else {
            $("#payment_name").css("display", "none");
        }
    });
    //获取收款码
    $("#form_submit").click(function (){
        var Load = layer.load(2, {shade: [0.3, '#000']}); //开始加载
        $.ajax({
            type: "POST",
            url: "/user/cashier_set/setInfo",
            data: $('#form_data').serialize(),
            dataType: "json",
            success: function (json) { //SUCCESS
                var data = $.parseJSON(json);
                if (data.code == 0) {
                    layer.close(Load); //关闭加载
                    var indexa = layer.msg(data.msg, {time: 1000, icon: 6}, function () {
                        layer.close(indexa);
                        window.location.reload();
                    });
                } else {
                    layer.close(Load); //关闭加载
                    var indexa = layer.alert(data.msg, {title: data.title, icon: 5}, function () {
                        layer.close(indexa);
                        if(data.url!="" && data.url!=null){
                            window.location.href=data.url;
                        }
                    })
                }
            },
            error: function () { //ERROR
                layer.close(Load); //关闭加载
                layer.msg('系统繁忙');
                return false;
            }
        });
    });
</script>